<template>
  <el-drawer v-model="visible" title="个人中心" size="40%">
    <div>
      <el-form :model="form">
        <el-form-item label="用户名" label-width="100px">
          <el-input v-model="form.name" />
        </el-form-item>
        <el-form-item label="密码" label-width="100px">
          <el-input v-model="form.password" type="password" />
        </el-form-item>
      </el-form>
      <div>
        <el-button type="primary" @click="updatePersionInfo"> 修改 </el-button>
      </div>
    </div>
  </el-drawer>
</template>
<script setup lang="ts" name="personal">
import { ref, reactive } from 'vue'
import { useUserInfo } from '@/stores/userInfo'

// 响应式获取useUserInfo的userInfos
const userInfoStore = useUserInfo()
const userInfos = userInfoStore.userInfos

const visible = ref(false)
const open = () => {
  visible.value = true
}

const form = reactive({
  name: '',
  password: '',
})

function updatePersionInfo() {
  form.name = userInfos.user.name
  console.log(userInfos.user)
}

// 暴露变量
defineExpose({
  open,
})
</script>

<style lang="css" scoped>
.el-drawer__body {
  height: 50px;
}
</style>
